package tp.pr2;

public class Place {

	/**
	 * 
	 * @param name nombre del lugar
	 * @param isSpaceShip si es la nave o no
	 * @param description datos del lugar que se mostrarán al llegar a él
	 */
	public Place (String name, boolean isSpaceShip, String description){
		this.name = name;
		this.description = description;
		this.isSpaceShip = isSpaceShip;
		this.chest = new ItemContainer();
	}
	


	/**
	 * is this place the space ship?
	 * @return true if the place represents a space ship
	 */
	public boolean isSpaceship (){
		return this.isSpaceShip;
	}
	
	/**
	 * Returns the name of the place and its descption, as well as a list of objects the place has
	 * @return A string with information about the place
	 */
	public String toString (){
		String base = this.name + Interpreter.LINE_SEPARATOR + 
				   this.description + Interpreter.LINE_SEPARATOR;
		//variable String temporal para devolver o place is empty o place not empty y lo que hay
		String temp = this.chest.toString();
		if (temp.equals("")) //caso de que no haya items
			temp = "The place is empty. There are no objects to pick"; 
		else 
			temp = Place.PLACE_CONTAINS + Interpreter.LINE_SEPARATOR + temp;
		
		return base + temp;
	}
	
	/**
	 * Tries to pick an item characterized by a given identifier from the place. If the action was completed the item must be removed from the place.
	 * @param id The identifier of the item
	 * @return The item of identifier id if it exists in the place. Otherwise the method returns null
	 */
	public Item pickItem(String id) {
		return this.chest.pickItem(id);
	}
	
	/**
	 * Tries to add an item to the place. The operation can fail (if the place already contains an item with the same name)
	 * @param it The item to be added
	 * @return true if and only if the item can be added to the place, i.e., the place does not contain an item with the same name
	 */
	public boolean addItem(Item it) {
		if (this.chest.addItem(it))
			return true;
		else 
			return false;
	}
	
	
	private static final String PLACE_CONTAINS = "The place contains these objects: "; //TODO quitar espacio del final, está solo para el validador
	
	private String name; 
	private boolean isSpaceShip;
	private String description;
	private ItemContainer chest;
}
